package top.bulk.encrypt.strategy;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 加密策略
 *
 * @author 散装java
 * @date 2024-07-18
 */
@Getter
@AllArgsConstructor
public enum CryptoStrategy {

    /**
     * 使用 aes 加密
     */
    AES {
        @Override
        public String encrypt(CryptoWrapper cryptoWrapper) {
            String fieldValue = cryptoWrapper.getFieldValue();
            String[] arguments = cryptoWrapper.getArguments();
            AES aes = SecureUtil.aes(arguments[0].getBytes());
            return aes.encryptHex(fieldValue);
        }

        @Override
        public String decrypt(CryptoWrapper cryptoWrapper) {
            String fieldValue = cryptoWrapper.getFieldValue();
            String[] arguments = cryptoWrapper.getArguments();

            AES aes = SecureUtil.aes(arguments[0].getBytes());
            return aes.decryptStr(fieldValue);
        }
    },
    ;

    public abstract String encrypt(CryptoWrapper cryptoWrapper);


    public abstract String decrypt(CryptoWrapper cryptoWrapper);
}
